package cn.com.zsw.gblog.modules.rocketmq;

import cn.com.zsw.gblog.modules.common.dto.LeaveMessageDTO;
import cn.com.zsw.gblog.modules.common.service.MailService;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author shiwangzhou
 * @date 2021-05-02
 **/
@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumer.group}", topic = "${rocketmq.topic}")
public class MqConsumer implements RocketMQListener<String> {
    @Resource
    MailService mailService;

    @Override
    public void onMessage(String message) {
        LeaveMessageDTO leaveMessageDTO = JSON.parseObject(message, LeaveMessageDTO.class);
        mailService.sendSimpleMail(leaveMessageDTO.getEmail(), "个人博客有人留言，请注意查看", leaveMessageDTO.getContent());

    }
}
